package com.gallop.akka.config;

import com.gallop.akka.AkkaProperties;

import java.util.ArrayList;
import java.util.List;

/**
 * 自定义Akka集群属性设置拦截器。
 * <p>
 * 在akka集群启动前，提供对{@link AkkaProperties}属性的编程方式修改
 */
public class AkkaPropInterceptors {

    private final List<InnerInterceptor> interceptors = new ArrayList<>();

    public <T> AkkaPropInterceptors addInterceptor(InnerInterceptor interceptor) {
        interceptors.add(interceptor);
        return this;
    }

    public void apply(AkkaProperties properties) {
        if (properties == null) {
            return;
        }
        this.interceptors.forEach(interceptor -> interceptor.apply(properties));
    }

    @FunctionalInterface
    public interface InnerInterceptor {
        void apply(AkkaProperties akkaProperties);
    }
}
